﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wd_13_shell_v1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        static string CMD_MAIN = "adb.exe";

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Process p = new Process();
            
            p.StartInfo.FileName = CMD_MAIN;
            p.StartInfo.Arguments = "devices";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();

            this.label1.Content = p.StandardOutput.ReadToEnd();

            p.Close();

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Process p = new Process();

            p.StartInfo.FileName = CMD_MAIN;
            p.StartInfo.Arguments = "kill-server";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();

            this.label1.Content = p.StandardOutput.ReadToEnd();

            p.Close();
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Process p = new Process();

            p.StartInfo.FileName = CMD_MAIN;
            p.StartInfo.Arguments = "start-server2";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            //this.label1.Content = p.StandardOutput.ReadToEnd();     // 结果有值，但打印为空？
            string output = string.Empty;
            output = p.StandardOutput.ReadToEnd();
            p.Close();
        }

        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Process p = new Process();

            p.StartInfo.FileName = CMD_MAIN;
            p.StartInfo.Arguments = "connect 192.168.1.167:5555";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            //this.label1.Content = p.StandardOutput.ReadToEnd();     // 结果有值，但打印为空？
            string output = string.Empty;
            output = p.StandardOutput.ReadToEnd();
            this.label1.Content = output;
            p.Close();
        }

        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            Process p = new Process();

            p.StartInfo.FileName = "taskkill";
            p.StartInfo.Arguments = "/f /im Everything.exe";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.CreateNoWindow = true;

            p.Start();
            //this.label1.Content = p.StandardOutput.ReadToEnd();     // 结果有值，但打印为空？
            string output = string.Empty;
            output = p.StandardOutput.ReadToEnd();
            this.label1.Content = output;
            p.Close();
        }
    }
}
